/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controllers;

import db.CustomerDB;
import db.CustomerInterface;
import db.InvoiceDb;
import db.InvoiceInterface;
import java.util.ArrayList;
import models.Customer;
import models.Invoice;
import models.Order;

/**
 *
 * @author pelle
 */
public class InvoiceController {

    private Invoice invoice = null;
    private InvoiceInterface invoiceDb = new InvoiceDb();
    private CustomerInterface customerDb = new CustomerDB();

    public InvoiceController() {
        invoice = new Invoice();
    }

    public InvoiceController(int invoiceId) {
        invoice = invoiceDb.getInvoice(invoiceId);
    }

    public void addCustomer(Customer customer) {
        invoice.setCustomer(customer);
    }

    public Customer getCustomer() {
        return invoice.getCustomer();
    }

    public void addOrders(ArrayList<Order> orders) {
        invoice.setOrders(orders);
    }

    public ArrayList<Order> getAvalibleOrders() {
        Customer cus = this.invoice.getCustomer();
        ArrayList<Order> orders = null;

        if(cus != null) {
            orders = this.customerDb.findNotInvoicedOrdersByCustomer(cus);
        }

        return orders;
    }

    public Invoice getInvoice() {
        return this.invoice;
    }

    public int createInvoice() {
        return this.invoiceDb.createInvoice(this.invoice);
    }
}
